<?php
namespace module\index\controller;

use app\Controller;
use app\model\Adv;
use app\model\Activity;
use app\model\Pay;
use app\model\UserNotice;
use EasyWeChat\Factory;

class Index extends Controller
{
    public function index()
    {
        $advs = Adv::where('status', 2)->select()->toArray();
        $activitys = Activity::field([
            'id', 'title', 'intro', 'origin_fee', 'fee', 'cover', 'tags',  // 活动内容'
        ])->limit(10)->select()->toArray();
        $activitys = array_map(fn($r) => $r + ['discount_rate' => sprintf("%.1f", $r['fee'] * 10 / $r['origin_fee'])], $activitys);
        $now = time();
        return json([
            'advs' => $advs,
            'notices' => UserNotice::field(['title', 'content'])->where([['status', '=', 2], ['start_at', '<', $now], ['end_at', '>', $now]])->select()->toArray(),
            'activitys' => $activitys
        ]);
    }
    /**
     * Undocumented function
     *
     * @return void
     */
    public function info(){
        return json(strrchr('manage.ibot', '.'));
    }
}
